<!doctype html>
<html>
<head>
    <meta charset="utf-8">
    <title>会员登陆</title>
    <meta name="viewport" content="width=device-width,initial-scale=1,user-scalable=0">
    <link rel="stylesheet" href="${contextPath}/staticwx/style/weui.css"/>
    <link rel="stylesheet" href="${contextPath}/staticwx/style/weui2.css"/>
    <link rel="stylesheet" href="${contextPath}/staticwx/style/weui3.css"/>
    <script src="${contextPath}/staticwx/zepto.min.js"></script>
    <script src="${contextPath}/staticwx/public.js"></script>
    <style>
        .weui_btn_grey{background-color:grey;}
    </style>
</head>

<body ontouchstart style="background-color: #f8f8f8;">
<form id="form">
    <div class="weui_cells weui_cells_form" style="margin-top: 0;">
        <div class="weui_cell">
            <div class="weui_cell_hd"><label class="weui_label">手机号码</label></div>
            <div class="weui_cell_bd weui_cell_primary">
                <input class="weui_input" type="text"  maxlength="11" placeholder="输入您的手机号码" name="loginName" id="loginName"/>
            </div>
            <div class="weui_cell_ft">
                <i class="weui_icon_warn"></i>
            </div>
        </div>

        <div class="weui_cell">
            <div class="weui_cell_hd"><label class="weui_label">密码</label></div>
            <div class="weui_cell_bd weui_cell_primary">
                <input class="weui_input" type="password"  maxlength="20" placeholder="请输入密码" name="password" id="password"/>
            </div>
            <div class="weui_cell_ft">
                <i class="weui_icon_warn"></i>
            </div>
        </div>
    </div>
    <div class="weui_btn_area" style="margin-top: 10px;">
        <a id="formSubmitBtn" href="javascript:" class="weui_btn weui_btn_primary" style="background: #FF8F09;">登录</a>
    </div>
</form>
<input type="hidden" id="sendEnable" value="1"/>

<script>
    $(function(){
        $("#formSubmitBtn").on("click",function () {
            var loginName=$("#loginName").val();
            if(loginName==''){
                showMsg("请输入手机号码");
                $("#loginName").focus();
                return false;
            }
            var password=$("#password").val();
            if(password==""){
                showMsg("密码不能为空");
                return false;
            }
            var sendEnable=$("#sendEnable").val();//防止多次请求
            if(sendEnable==1){
                $("#sendEnable").val(0);
                doLogin(loginName,password);//处理登陆操作
            }
        });
    })
    function  doLogin(loginName,password) {
        $.ajax({
            url : '${contextPath}/wx/doLogin.htm',
            data : {
                loginName :loginName,
                password:password
            },
            type : 'post',
            cache : false,
            dataType : 'json',
            success : function(data) {
                var json = $.parseJSON(data);
                if (json.isSuccess == true) {
                    location.href="${contextPath}/wx/index.htm";
                } else {
                    showMsg(json.errMessage);
                }
            },
            error : function() {
                showMsg("异常");
            }
        });
    }

    function  checkCode(tel,code) {
        $.ajax({
            url : '${contextPath}/wx/msg/checkCode.htm',
            data : {
                tel : tel,
                code:code
            },
            type : 'post',
            cache : false,
            dataType : 'json',
            success : function(data) {
                var json = $.parseJSON(data);
                if (json.isSuccess == true) {
                    var mid=$("#mid").val();
                    var cid=$("#cityId").val();
                    var pid=$("#pid").val();
                    var password=$("#password").val();
                    doBind(mid,pid,cid,tel,password);
                } else {
                    showMsg(json.errMessage);
                }
            },
            error : function() {
                showMsg("异常");
            }
        });
    }

    function  doBind(mid,pid,cid,tel,password) {
        $.ajax({
            url : '${contextPath}/wx/doBind.htm',
            data : {
                tel:tel,
                mid:mid,
                pid:pid,
                cid:cid,
                password:password
            },
            type : 'post',
            cache : false,
            dataType : 'json',
            success : function(data) {
                var json = $.parseJSON(data);
                if (json.isSuccess == true) {
                    showMsg("提交成功");
                    location.href="${contextPath}/wx/drainage.htm?mid="+mid;
                 } else {
                    showMsg(json.errMessage);
                }
            },
            error : function() {
                showMsg("异常");
            }
        });
    }
</script>
</body>
</html>